package day06Case01;

/**
 * @author Xiao
 * @date 2021/7/6
 */
public class getSumAve_Array {
    /**
     *      需求：
     *          获取任意数组中的元素和，并返回
     */
    public static void main(String[] args) {
        int[] arr = Print_Array.getAnyArray();
        System.out.println("产生的随机int类型数组如下：");
        Print_Array.printArray(arr);
        System.out.println("-----------------");
        int sum = getSumArray(arr);
        System.out.println("sum:" + sum);
        int ave = getAve_Array(arr, sum);
        System.out.println("ave:" + ave);
    }

    public static int getAve_Array(int[] arr, int sum) {
        int ave = sum / arr.length;
        return ave;
    }

    public static int getSumArray(int[] arr) {
        if (arr == null) {
            return -1;
        }else {
            int sum = 0;
            for (int i = 0; i < arr.length; i++) {
                sum += arr[i];
            }
            return sum;
        }
    }
}
